#include <bits/stdc++.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>

using namespace std;

string testFile = "/data/test_data.txt";
string resultFile = "/projects/student/result.txt";

typedef struct Node{
	int id;
	uint pay;
	bool operator<(const Node &other)const{
		return id<other.id;
	}
	bool operator==(const Node &other)const{
		return id==other.id;
	}
}Node;

/*构建图需要的变量*/
int account_num = 0;
uint inputs[2*2000000];
uint accts[2*2000000];
vector<Node> G[2000000];
vector<int> RG[2000000];
/**********************/

pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;

/*写文件时需要的变量*/
char account_chars[2000000][12];
short length[2000000];
char buf[77*20000000];
/**********************/

/*线程1变量*/
int head_1;
int ans3_1[100000][3], p3_1=0;//10万
int ans4_1[100000][4], p4_1=0;
int ans5_1[100000][5], p5_1=0;
int ans6_1[8000000][6], p6_1=0;//100万
int ans7_1[15000000][7], p7_1=0;//1200万
bool vis_1[2000000];
int reachable_1[2000000];
int path_1[7];
/**********************/

/*线程2变量*/
int head_2;
int ans3_2[100000][3], p3_2=0;//10万
int ans4_2[100000][4], p4_2=0;
int ans5_2[100000][5], p5_2=0;
int ans6_2[8000000][6], p6_2=0;//100万
int ans7_2[15000000][7], p7_2=0;//1200万
bool vis_2[2000000];
int reachable_2[2000000];
int path_2[7];
/**********************/

/*线程3变量*/
int head_3;
int ans3_3[100000][3], p3_3=0;//10万
int ans4_3[100000][4], p4_3=0;
int ans5_3[100000][5], p5_3=0;
int ans6_3[8000000][6], p6_3=0;//100万
int ans7_3[15000000][7], p7_3=0;//1200万
bool vis_3[2000000];
int reachable_3[2000000];
int path_3[7];
/**********************/

/*线程4变量*/
int head_4;
int ans3_4[100000][3], p3_4=0;//10万
int ans4_4[100000][4], p4_4=0;
int ans5_4[100000][5], p5_4=0;
int ans6_4[8000000][6], p6_4=0;//100万
int ans7_4[15000000][7], p7_4=0;//1200万
bool vis_4[2000000];
int reachable_4[2000000];
int path_4[7];
/**********************/

uint parse_1(char** s){
	char *p = *s;
	uint val = *(p++) - '0';
	while(*p != ',') val = 10*val + *(p++) - '0';
	*s = p+1;
	return val;
}
uint parse_2(char** s){
	char *p = *s;
	uint val = *(p++) - '0';
	while(*p != '\r' && *p != '\n') val = 10*val + *(p++) - '0';
	*s = *p=='\r' ? p+2:p+1;
	return val;
}
void parse_to_char(uint a, char *tmp, int &k){
	int n=0;
	do{tmp[n++] = a%10+'0';}while((a/=10)>0);
	reverse(tmp, tmp+n);
	tmp[n++]=',';
	length[k]=n;
}
void loadData_and_createGrap(){
	int fd = open(testFile.c_str(), O_RDONLY);
    int size = lseek(fd, 0, SEEK_END);
    char* p_map =(char*)mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
    close(fd);
	char *p = p_map;
	int n=0;//n表示文件中的记录数
	uint money[2000000];
	while(*p != '\0'){
		inputs[n]=parse_1(&p);
		inputs[n+2000000]=parse_1(&p);
		money[n++]=parse_2(&p);
	}
	memcpy(accts, inputs, 4*n);
	memcpy(accts+n, inputs+2000000, 4*n);  
	sort(accts, accts+2*n);//排序
	account_num = unique(accts, accts+2*n) - accts;//去重
	unordered_map<uint, int> idHash;
	for(int i=0; i<account_num; i++)idHash[accts[i]]=i;
	Node node;
	for(int i=0,a=0,b=0, m=0; i<n; ++i,++m){
		a=idHash[inputs[i+0]];
		b=idHash[inputs[i+2000000]];
		if(a==b) continue;
		G[a].push_back(Node{b,money[m]});
		RG[b].push_back(a);
	}
	for(int i=0; i<account_num; i++) {sort(G[i].begin(),G[i].end());parse_to_char(accts[i],account_chars[i],i);}
	munmap(p_map, size);
}

inline bool check(const uint &x, const uint &y){
	return x<=5ll*y && y<=3ll*x;
}

/*线程1*/
uint pay_1;
void dfs_1(int &head, int &cur, Node &last, int dep){
	path_1[dep-1]=cur;
	int v;
	for(Node &each:G[cur]){
		if(dep==1) pay_1=each.pay;//记下这第一笔转账
		if(dep>1 && !check(last.pay, each.pay)) continue;
		v = each.id;
		if(v==head && dep>2){
			if(check(each.pay, pay_1)){
				switch(dep){
					case 3:
						memcpy(ans3_1[p3_1++], path_1, 12);
						break;
					case 4:
						memcpy(ans4_1[p4_1++], path_1, 16);
						break;
					case 5:
						memcpy(ans5_1[p5_1++], path_1, 20);
						break;
					case 6:
						memcpy(ans6_1[p6_1++], path_1, 24);
						break;
				}
			}
			continue;
		}
		if(dep==6 || reachable_1[v]!=head || vis_1[v]) continue;
		vis_1[cur] = true;
		dfs_1(head, v, each, dep+1);
		vis_1[cur] = false;
	}
}
void clip_1(int &head, int &cur, int dep){
	int v;
	for(Node &each:G[cur]){
		v = each.id;
		if(v < head || vis_1[v]) continue;
		reachable_1[v] = head;
		if(dep == 2) continue;
		vis_1[cur] = true;
		clip_1(head, v, dep+1);
		vis_1[cur] = false;
	}
}
void rclip_1(int &head, int &cur, int dep){
	for(int &v:RG[cur]){
		if(v < head || vis_1[v]) continue;
		reachable_1[v] = head;
		if(dep == 3) continue;
		vis_1[cur] = true;
		rclip_1(head, v, dep+1);
		vis_1[cur] = false;
	}
}
void loop_1(int &u){
	path_1[0]=u;
	int v1,v2,v3,v4,v5,v6;
	vector<Node>::iterator node7;
	for(Node &node1:G[u]){
		v1=node1.id; if(reachable_1[v1]!=u) continue;
		for(Node &node2:G[v1]){
			v2=node2.id; if(reachable_1[v2]!=u || !check(node1.pay, node2.pay)) continue;
			for(Node &node3:G[v2]){
				v3=node3.id; if(v3<u || v3==v1 || v3==u || !check(node2.pay, node3.pay)) continue;
				for(Node &node4:G[v3]){
					v4=node4.id; if(reachable_1[v4]!=u || v4==v2 || v4==v1 || !check(node3.pay, node4.pay)) continue;
					for(Node &node5:G[v4]){
						v5=node5.id; if(reachable_1[v5]!=u || v5==v3 || v5==v2 || v5==v1  || !check(node4.pay, node5.pay)) continue;
						for(Node &node6:G[v5]){
							v6=node6.id; if(reachable_1[v6]!=u) continue;
							if(!check(node5.pay, node6.pay)||v6==v1 || v6==v2 || v6==v3 || v6==v4) continue;
							node7 = find(G[v6].begin(),G[v6].end(), Node{u,0});
							if(node7==G[v6].end() || !check(node6.pay, node7->pay)) continue;
							if(!check(node7->pay, node1.pay)) continue;
							path_1[1]=v1;
							path_1[2]=v2;
							path_1[3]=v3;
							path_1[4]=v4;
							path_1[5]=v5;
							path_1[6]=v6;
							memcpy(ans7_1[p7_1++], path_1, 28);
						}
					}
				}
			}
		}
	}
}

/*线程2*/
uint pay_2;
void dfs_2(int &head, int &cur, Node &last, int dep){
	path_2[dep-1]=cur;
	int v;
	for(int i=G[cur].size(); i>0; ){//反向遍历，反正很神奇，自己体会吧
		Node &each=G[cur][--i];
		if(dep==1) pay_2=each.pay;//记下这第一笔转账
		if(dep>1 && !check(last.pay, each.pay)) continue;
		v = each.id;
		if(v==head && dep>2){
			if(check(each.pay, pay_2)){
				switch(dep){
					case 3:
						memcpy(ans3_2[p3_2++], path_2, 12);
						break;
					case 4:
						memcpy(ans4_2[p4_2++], path_2, 16);
						break;
					case 5:
						memcpy(ans5_2[p5_2++], path_2, 20);
						break;
					case 6:
						memcpy(ans6_2[p6_2++], path_2, 24);
						break;
				}
			}
			continue;
		}
		if(dep==6 || reachable_2[v]!=head || vis_2[v]) continue;
		vis_2[cur] = true;
		dfs_2(head, v, each, dep+1);
		vis_2[cur] = false;
	}
}
void clip_2(int &head, int &cur, int dep){
	int v;
	for(Node &each:G[cur]){
		v = each.id;
		if(v < head || vis_2[v]) continue;
		reachable_2[v] = head;
		if(dep == 2) continue;
		vis_2[cur] = true;
		clip_2(head, v, dep+1);
		vis_2[cur] = false;
	}
}
void rclip_2(int &head, int &cur, int dep){
	for(int &v:RG[cur]){
		if(v < head || vis_2[v]) continue;
		reachable_2[v] = head;
		if(dep == 3) continue;
		vis_2[cur] = true;
		rclip_2(head, v, dep+1);
		vis_2[cur] = false;
	}
}
void loop_2(int &u){
	path_2[0]=u;
	int v1,v2,v3,v4,v5,v6;
	vector<Node>::iterator node7;
	for(auto node1=G[u].rbegin(); node1!=G[u].rend(); node1++){
		v1=(*node1).id; if(reachable_2[v1]!=u) continue;
		for(auto node2=G[v1].rbegin(); node2!=G[v1].rend(); node2++){
			v2=(*node2).id; if(reachable_2[v2]!=u || !check((*node1).pay, (*node2).pay)) continue;
			for(auto node3=G[v2].rbegin(); node3!=G[v2].rend(); node3++){
				v3=(*node3).id; if(v3<u || v3==v1 || v3==u || !check((*node2).pay, (*node3).pay)) continue;
				for(auto node4=G[v3].rbegin(); node4!=G[v3].rend(); node4++){
					v4=(*node4).id; if(reachable_2[v4]!=u || v4==v2 || v4==v1 || !check((*node3).pay, (*node4).pay)) continue;
					for(auto node5=G[v4].rbegin(); node5!=G[v4].rend(); node5++){
						v5=(*node5).id; if(reachable_2[v5]!=u || v5==v3 || v5==v2 || v5==v1  || !check((*node4).pay, (*node5).pay)) continue;
						for(auto node6=G[v5].rbegin(); node6!=G[v5].rend(); node6++){
							v6=(*node6).id; if(reachable_2[v6]!=u) continue;
							if(!check((*node5).pay, (*node6).pay)||v6==v1 || v6==v2 || v6==v3 || v6==v4) continue;
							node7 = find(G[v6].begin(),G[v6].end(), Node{u,0});
							if(node7==G[v6].end() || !check((*node6).pay, node7->pay)) continue;
							if(!check(node7->pay, (*node1).pay)) continue;
							path_2[1]=v1;
							path_2[2]=v2;
							path_2[3]=v3;
							path_2[4]=v4;
							path_2[5]=v5;
							path_2[6]=v6;
							memcpy(ans7_2[p7_2++], path_2, 28);
						}
					}
				}
			}
		}
	}
}

/*线程3*/
uint pay_3;
void dfs_3(int &head, int &cur, Node &last, int dep){
	path_3[dep-1]=cur;
	int v;
	for(Node &each:G[cur]){
		if(dep==1) pay_3=each.pay;//记下这第一笔转账
		if(dep>1 && !check(last.pay, each.pay)) continue;
		v = each.id;
		if(v==head && dep>2){
			if(check(each.pay, pay_3)){
				switch(dep){
					case 3:
						memcpy(ans3_3[p3_3++], path_3, 12);
						break;
					case 4:
						memcpy(ans4_3[p4_3++], path_3, 16);
						break;
					case 5:
						memcpy(ans5_3[p5_3++], path_3, 20);
						break;
					case 6:
						memcpy(ans6_3[p6_3++], path_3, 24);
						break;
				}
			}
			continue;
		}
		if(dep==6 || reachable_3[v]!=head || vis_3[v]) continue;
		vis_3[cur] = true;
		dfs_3(head, v, each, dep+1);
		vis_3[cur] = false;
	}
}
void clip_3(int &head, int &cur, int dep){
	int v;
	for(Node &each:G[cur]){
		v = each.id;
		if(v < head || vis_3[v]) continue;
		reachable_3[v] = head;
		if(dep == 2) continue;
		vis_3[cur] = true;
		clip_3(head, v, dep+1);
		vis_3[cur] = false;
	}
}
void rclip_3(int &head, int &cur, int dep){
	for(int &v:RG[cur]){
		if(v < head || vis_3[v]) continue;
		reachable_3[v] = head;
		if(dep == 3) continue;
		vis_3[cur] = true;
		rclip_3(head, v, dep+1);
		vis_3[cur] = false;
	}
}
void loop_3(int &u){
	path_3[0]=u;
	int v1,v2,v3,v4,v5,v6;
	vector<Node>::iterator node7;
	for(Node &node1:G[u]){
		v1=node1.id; if(reachable_3[v1]!=u) continue;
		for(Node &node2:G[v1]){
			v2=node2.id; if(reachable_3[v2]!=u || !check(node1.pay, node2.pay)) continue;
			for(Node &node3:G[v2]){
				v3=node3.id; if(v3<u || v3==v1 || v3==u || !check(node2.pay, node3.pay)) continue;
				for(Node &node4:G[v3]){
					v4=node4.id; if(reachable_3[v4]!=u || v4==v2 || v4==v1 || !check(node3.pay, node4.pay)) continue;
					for(Node &node5:G[v4]){
						v5=node5.id; if(reachable_3[v5]!=u || v5==v3 || v5==v2 || v5==v1  || !check(node4.pay, node5.pay)) continue;
						for(Node &node6:G[v5]){
							v6=node6.id; if(reachable_3[v6]!=u) continue;
							if(!check(node5.pay, node6.pay)||v6==v1 || v6==v2 || v6==v3 || v6==v4) continue;
							node7 = find(G[v6].begin(),G[v6].end(), Node{u,0});
							if(node7==G[v6].end() || !check(node6.pay, node7->pay)) continue;
							if(!check(node7->pay, node1.pay)) continue;
							path_3[1]=v1;
							path_3[2]=v2;
							path_3[3]=v3;
							path_3[4]=v4;
							path_3[5]=v5;
							path_3[6]=v6;
							memcpy(ans7_3[p7_3++], path_3, 28);
						}
					}
				}
			}
		}
	}
}

/*线程3*/
uint pay_4;
void dfs_4(int &head, int &cur, Node &last, int dep){
	path_4[dep-1]=cur;
	int v;
	for(int i=G[cur].size(); i>0; ){//反向遍历，反正很神奇，自己体会吧
		Node &each=G[cur][--i];
		if(dep==1) pay_4=each.pay;//记下这第一笔转账
		if(dep>1 && !check(last.pay, each.pay)) continue;
		v = each.id;
		if(v==head && dep>2){
			if(check(each.pay, pay_4)){
				switch(dep){
					case 3:
						memcpy(ans3_4[p3_4++], path_4, 12);
						break;
					case 4:
						memcpy(ans4_4[p4_4++], path_4, 16);
						break;
					case 5:
						memcpy(ans5_4[p5_4++], path_4, 20);
						break;
					case 6:
						memcpy(ans6_4[p6_4++], path_4, 24);
						break;
				}
			}
			continue;
		}
		if(dep==6 || reachable_4[v]!=head || vis_4[v]) continue;
		vis_4[cur] = true;
		dfs_4(head, v, each, dep+1);
		vis_4[cur] = false;
	}
}
void clip_4(int &head, int &cur, int dep){
	int v;
	for(Node &each:G[cur]){
		v = each.id;
		if(v < head || vis_4[v]) continue;
		reachable_4[v] = head;
		if(dep == 2) continue;
		vis_4[cur] = true;
		clip_4(head, v, dep+1);
		vis_4[cur] = false;
	}
}
void rclip_4(int &head, int &cur, int dep){
	for(int &v:RG[cur]){
		if(v < head || vis_4[v]) continue;
		reachable_4[v] = head;
		if(dep == 3) continue;
		vis_4[cur] = true;
		rclip_4(head, v, dep+1);
		vis_4[cur] = false;
	}
}
void loop_4(int &u){
	path_4[0]=u;
	int v1,v2,v3,v4,v5,v6;
	vector<Node>::iterator node7;
	for(auto node1=G[u].rbegin(); node1!=G[u].rend(); node1++){
		v1=(*node1).id; if(reachable_4[v1]!=u) continue;
		for(auto node2=G[v1].rbegin(); node2!=G[v1].rend(); node2++){
			v2=(*node2).id; if(reachable_4[v2]!=u || !check((*node1).pay, (*node2).pay)) continue;
			for(auto node3=G[v2].rbegin(); node3!=G[v2].rend(); node3++){
				v3=(*node3).id; if(v3<u || v3==v1 || v3==u || !check((*node2).pay, (*node3).pay)) continue;
				for(auto node4=G[v3].rbegin(); node4!=G[v3].rend(); node4++){
					v4=(*node4).id; if(reachable_4[v4]!=u || v4==v2 || v4==v1 || !check((*node3).pay, (*node4).pay)) continue;
					for(auto node5=G[v4].rbegin(); node5!=G[v4].rend(); node5++){
						v5=(*node5).id; if(reachable_4[v5]!=u || v5==v3 || v5==v2 || v5==v1  || !check((*node4).pay, (*node5).pay)) continue;
						for(auto node6=G[v5].rbegin(); node6!=G[v5].rend(); node6++){
							v6=(*node6).id; if(reachable_4[v6]!=u) continue;
							if(!check((*node5).pay, (*node6).pay)||v6==v1 || v6==v2 || v6==v3 || v6==v4) continue;
							node7 = find(G[v6].begin(),G[v6].end(), Node{u,0});
							if(node7==G[v6].end() || !check((*node6).pay, node7->pay)) continue;
							if(!check(node7->pay, (*node1).pay)) continue;
							path_4[1]=v1;
							path_4[2]=v2;
							path_4[3]=v3;
							path_4[4]=v4;
							path_4[5]=v5;
							path_4[6]=v6;
							memcpy(ans7_4[p7_4++], path_4, 28);
						}
					}
				}
			}
		}
	}
}


void solve_1(void){
	bool flag = false;
	memset(vis_1, 0, sizeof(vis_1));
	memset(reachable_1, -1, sizeof(reachable_1));
	Node tmp;
	while(1){
		pthread_mutex_lock(&g_mutex);
		if((head_2 - head_1) <= 1) flag=true;
        head_1++;
        pthread_mutex_unlock(&g_mutex);
        if(flag) break;
		if(G[head_1].size()<1 || RG[head_1].size()<1) continue;
		clip_1(head_1,head_1,1);
		rclip_1(head_1,head_1,1);
		dfs_1(head_1,head_1,tmp,1);
		loop_1(head_1);
	}
}

void solve_2(void){
	bool flag = false;
	memset(vis_2, 0, sizeof(vis_2));
	memset(reachable_2, -1, sizeof(reachable_2));
	Node tmp;
	while(1){
		pthread_mutex_lock(&g_mutex);
		if((head_2 - head_1) <= 1) flag=true;
        head_2--;
        pthread_mutex_unlock(&g_mutex);
        if(flag) break;
		if(G[head_2].size()<1 || RG[head_2].size()<1) continue;
		clip_2(head_2,head_2,1);
		rclip_2(head_2,head_2,1);
		dfs_2(head_2,head_2,tmp,1);
		loop_2(head_2);
	}
}

void solve_3(void){
	bool flag = false;
	memset(vis_3, 0, sizeof(vis_3));
	memset(reachable_3, -1, sizeof(reachable_3));
	Node tmp;
	while(1){
		pthread_mutex_lock(&g_mutex);
		if((head_4 - head_3) <= 1) flag=true;
        head_3++;
        pthread_mutex_unlock(&g_mutex);
        if(flag) break;
		if(G[head_3].size()<1 || RG[head_3].size()<1) continue;
		clip_3(head_3,head_3,1);
		rclip_3(head_3,head_3,1);
		dfs_3(head_3,head_3,tmp,1);
		loop_3(head_3);
	}
}

void solve_4(void){
	bool flag = false;
	memset(vis_4, 0, sizeof(vis_4));
	memset(reachable_4, -1, sizeof(reachable_4));
	Node tmp;
	while(1){
		pthread_mutex_lock(&g_mutex);
		if((head_4 - head_3) <= 1) flag=true;
        head_4--;
        pthread_mutex_unlock(&g_mutex);
        if(flag) break;
		if(G[head_4].size()<1 || RG[head_4].size()<1) continue;
		clip_4(head_4,head_4,1);
		rclip_4(head_4,head_4,1);
		dfs_4(head_4,head_4,tmp,1);
		loop_4(head_4);
	}
}

void save(){
	int all = p3_1+p4_1+p5_1+p6_1+p7_1+p3_2+p4_2+p5_2+p6_2+p7_2+p3_3+p4_3+p5_3+p6_3+p7_3+p3_4+p4_4+p5_4+p6_4+p7_4;
	int n=sprintf(buf,"%d\n",all);
	int i, j, v;
	
	for(i=0; i<p3_1; i++){
		for(j=0; j<3; j++){
			v=ans3_1[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=p3_2-1; i>-1; --i){
		for(j=0; j<3; j++){
			v=ans3_2[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=0; i<p3_3; i++){
		for(j=0; j<3; j++){
			v=ans3_3[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=p3_4-1; i>-1; --i){
		for(j=0; j<3; j++){
			v=ans3_4[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	
	for(i=0; i<p4_1; i++){
		for(j=0; j<4; j++){
			v=ans4_1[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=p4_2-1; i>-1; --i){
		for(j=0; j<4; j++){
			v=ans4_2[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=0; i<p4_3; i++){
		for(j=0; j<4; j++){
			v=ans4_3[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=p4_4-1; i>-1; --i){
		for(j=0; j<4; j++){
			v=ans4_4[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	
	for(i=0; i<p5_1; i++){
		for(j=0; j<5; j++){
			v=ans5_1[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=p5_2-1; i>-1; --i){
		for(j=0; j<5; j++){
			v=ans5_2[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=0; i<p5_3; i++){
		for(j=0; j<5; j++){
			v=ans5_3[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=p5_4-1; i>-1; --i){
		for(j=0; j<5; j++){
			v=ans5_4[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	
	for(i=0; i<p6_1; i++){
		for(j=0; j<6; j++){
			v=ans6_1[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=p6_2-1; i>-1; --i){
		for(j=0; j<6; j++){
			v=ans6_2[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=0; i<p6_3; i++){
		for(j=0; j<6; j++){
			v=ans6_3[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=p6_4-1; i>-1; --i){
		for(j=0; j<6; j++){
			v=ans6_4[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	
	for(i=0; i<p7_1; i++){
		for(j=0; j<7; j++){
			v=ans7_1[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=p7_2-1; i>-1; --i){
		for(j=0; j<7; j++){
			v=ans7_2[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=0; i<p7_3; i++){
		for(j=0; j<7; j++){
			v=ans7_3[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	for(i=p7_4-1; i>-1; --i){
		for(j=0; j<7; j++){
			v=ans7_4[i][j];
			memcpy(buf+n, account_chars[v], length[v]);
			n+=length[v];
		}
		buf[n-1]='\n';
	}
	
	int fd = open(resultFile.c_str(), O_RDWR|O_CREAT, 0666);
	lseek(fd, n-1, SEEK_SET);
	write(fd, "", 1);
	char* p_map =(char*)mmap(NULL, n, PROT_WRITE, MAP_SHARED, fd, 0);
	memcpy(p_map, buf, n);
	munmap(p_map, n);
	close(fd);
}

int main(int argc, char* argv[]){
	loadData_and_createGrap();
	head_1 = -1;
	head_2 = account_num*0.114;
	head_3 = head_2 - 1;
	head_4 = account_num;
	vector<thread> threadpool(4);
	threadpool[0] = thread(&solve_1);
	threadpool[1] = thread(&solve_2);
	threadpool[2] = thread(&solve_3);
	threadpool[3] = thread(&solve_4);
	threadpool[0].join();
	threadpool[1].join();
	threadpool[2].join();
	threadpool[3].join();
	save();
	exit(0);
}